package com.example.rbacmanage.util;

import java.lang.reflect.Field;

public class ReflectUtil {
    public static boolean areEqual(Object obj1, Object obj2) {
        if (obj1 == obj2) return true;
        if (obj1 == null || obj2 == null) return false;
        if (obj1.getClass() != obj2.getClass()) return false;

        Field[] fields = obj1.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true); // 确保可以访问私有字段
            try {
                Object value1 = field.get(obj1);
                Object value2 = field.get(obj2);
                if (value1 == null) {
                    if (value2 != null) return false;
                } else {
                    if (!value1.equals(value2)) return false;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }
}
